package com.tql;

import redis.clients.jedis.Jedis;

public class TestSet {
    public static void main(String[] args) {
        Jedis jedis=new Jedis("127.0.0.1",6379);
        jedis.flushDB();
        System.out.println("可以非常方便的实现如共同关注、共同喜好、二度好友等功能");
        System.out.println("set 特点 无需切不可重复 用于发现好友等，没有重复");
        System.out.println(jedis.sadd("set1","a","b","c","d"));
        System.out.println(jedis.sadd("set2","a","b","c","d"));
        System.out.println(jedis.sadd("set3","a","b","c","d"));
        System.out.println("查看set1的所有的元素"+jedis.smembers("set1"));
        System.out.println("删除一个元素"+jedis.srem("set1","a"));
        System.out.println("查看"+jedis.smembers("set1"));
        System.out.println("删除俩个元素"+jedis.srem("set2","a","b"));
        System.out.println("查看"+jedis.smembers("set2"));
        System.out.println("随机一处一个数据"+jedis.spop("set3"));
        System.out.println("查看"+jedis.smembers("set3"));
        System.out.println("集合元素个数"+jedis.scard("set3"));
        System.out.println("判断一个元素是否存在"+jedis.sismember("set3","a"));
        jedis.flushDB();
        System.out.println(jedis.sadd("set1","a","b","c","d","t"));
        System.out.println(jedis.sadd("set2","a","b","c","d","h","j","ke"));
        System.out.println(jedis.sadd("set3","a","b","x","y","z","w","x"));
        System.out.println("set1 删除 t 移入set2中"+jedis.smove("set1","set2","t"));
        System.out.println(jedis.smembers("set1"));
        System.out.println(jedis.smembers("set2"));
        System.out.println("求set1 和set2 的交集"+jedis.sinter("set1","set2"));
        System.out.println("求set1和set2的并集"+jedis.sunion("set1","set2"));
        System.out.println("求茶几"+jedis.sdiff("set2","set1"));
        System.out.println("求交集并存入dstkey中"+jedis.sinterstore("set4","set1","set3"));
        System.out.println(jedis.smembers("set4"));

    }
}
